/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package filmlibrary.web;

import filmlibrary.orm.ORMHelper;
import filmlibrary.orm.classes.Films;
import filmlibrary.orm.classes.Genres;
import filmlibrary.orm.classes.Quality;
import java.util.List;
import java.util.ArrayList;
import java.util.logging.Logger;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

/**
 *
 * @author karol
 */
@ManagedBean
@RequestScoped
public class SearchBean {
    private static final Logger logger = Logger.getLogger(SearchBean.class.getName());
    ORMHelper orm = new ORMHelper();
    String filmName="";
    String user="";
    String quality="";
    private String[] genre = {""};
    int sizeFrom=0;
    int sizeTo=0;
    int yearFrom=0;
    int yearTo=0;
    int rankFrom=0;
    int rankTo=0;
    List<Films> f=null;
    
    List<Integer> ranks=null;
    List<Genres> genres=null;
    List<Integer> years=null;
    List<String> users=null;
    List<Quality> qualities=null;
    /** Creates a new instance of SearchBean */
    public SearchBean() {                
        ranks = getRanksFromDB();
        genres = getGenresFromDB();
        years = getYearsFromDB();
        qualities = getQualitiesFromDB();
        users = getUsersFromDB();
    }

    public void search(){
        this.f= orm.getSearchResult(this);
        //return "search_result";

    }

    private List<Integer> getRanksFromDB(){
        List<Integer> ranks = new ArrayList(10);
        for(int i=1;i<=10;++i){
            ranks.add(i);
        }
        return ranks;
    }

    private List<Genres> getGenresFromDB(){
        List<Genres> g = orm.getGenres();        
        return g;
    }

    private List<Integer> getYearsFromDB()
    {
        List<Integer> mm = new ArrayList();
        Integer[] yearSpan =  orm.getMaxMinYear();
        for(int i = yearSpan[1];i>=yearSpan[0];--i)
        {
            mm.add(i);
        }
       
        return mm;
    }

    private List<String> getUsersFromDB()
    {
        return orm.getUsers();
    }
    private List<Quality> getQualitiesFromDB(){
        return orm.getQualities();
    }
    
    public int getYearFrom() {
        return yearFrom;
    }

    public void setYearFrom(int yearFrom) {
        this.yearFrom = yearFrom;
    }

    public int getYearTo() {
        return yearTo;
    }

    public void setYearTo(int yearTo) {
        this.yearTo = yearTo;
    }

    public int getSizeFrom() {
        return sizeFrom;
    }

    public void setSizeFrom(int sizeFrom) {
        this.sizeFrom = sizeFrom;
    }

    public int getSizeTo() {
        return sizeTo;
    }

    public void setSizeTo(int sizeTo) {
        this.sizeTo = sizeTo;
    }

     public String[] getGenre() {
        return (String[]) genre.clone();
    }
    
    public void setGenre(String genre[]) {
        this.genre = (String[]) genre.clone();
    }

    public String getQuality() {
        return quality;
    }

    public void setQuality(String quality) {
        this.quality = quality;
    }


    public String getUser() {
        return user;
    }

    public void setUser(String user) {
        this.user = user;
    }

    public int getRankFrom() {
        return rankFrom;
    }

    public void setRankFrom(int rankFrom) {
        this.rankFrom = rankFrom;
    }

    public int getRankTo() {
        return rankTo;
    }

    public void setRankTo(int rankTo) {
        this.rankTo = rankTo;
    }
    
    public String getFilmName() {
        return filmName;
    }

    public void setFilmName(String filmName) {
        this.filmName = filmName;
    }

    public List<Films> getF() {
        return f;
    }

    public void setF(List<Films> f) {
        this.f = f;
    }

    public List<Integer> getYears() {
        return years;
    }

    public void setYears(List<Integer> years) {
        this.years = years;
    }

    public List<Genres> getGenres() {
        return genres;
    }

    public void setGenres(List<Genres> genres) {
        this.genres = genres;
    }

    public List<Quality> getQualities() {
        return qualities;
    }

    public void setQualities(List<Quality> qualities) {
        this.qualities = qualities;
    }

    public List<Integer> getRanks() {
        return ranks;
    }

    public void setRanks(List<Integer> ranks) {
        this.ranks = ranks;
    }

    public List<String> getUsers() {
        return users;
    }

    public void setUsers(List<String> users) {
        this.users = users;
    }
    
}
